package cn.lxh.controller.app;


import cn.dev33.satoken.annotation.SaIgnore;
import cn.lxh.pojo.app.dto.LocationDto;
import cn.lxh.pojo.app.dto.WXCodeDto;
import cn.lxh.result.JSONResult;
import cn.lxh.service.IDriverService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * AppDriverController控制层
 */
@Tag(name = "App司机对象", description = "App司机对象")
@RestController
@RequestMapping("/app/driver")
public class AppDriverController {

    @Autowired
    public IDriverService driverService;

    @Operation(summary = "司机微信注册", description = "司机微信注册")
    @Parameter(name = "微信Code", description = "微信Code", required = true)
    @PostMapping("/mp/register")
    @SaIgnore // 不做登录校验
    public JSONResult mpRegister(@RequestBody @Valid WXCodeDto wxCodeDto) {
        return JSONResult.success(driverService.mpRegister(wxCodeDto));
    }

    @Operation(summary = "获取当前司机的工作台数据", description = "获取当前司机的工作台数据")
    @GetMapping("/getWorkbenchData")
    public JSONResult getWorkbenchData() {
        return JSONResult.success(driverService.getWorkbenchData());
    }

    @Operation(summary = "司机上线开始接单", description = "司机上线开始接单")
    @PostMapping("/online")
    public JSONResult online() {
        return JSONResult.success(driverService.online());
    }

    @Operation(summary = "司机下线停止接单", description = "司机下线停止接单")
    @PostMapping("/offline")
    public JSONResult offline() {
        return JSONResult.success(driverService.offline());
    }

    @Operation(summary = "保存司机坐标到GEO", description = "保存司机坐标到GEO")
    @Parameter(name = "locationDto", description = "坐标参数", required = true)
    @PostMapping("/saveGEO")
    public JSONResult saveGEO(@RequestBody @Valid LocationDto locationDto) {
        return JSONResult.success(driverService.saveGEO(locationDto));
    }

    @Operation(summary = "删除当前司机Geo", description = "删除当前司机Geo")
    @DeleteMapping("/deleteDriverGeo")
    public JSONResult deleteDriverGeo() {
        return JSONResult.success(driverService.deleteDriverGeo());
    }

    @Operation(summary = "保存司机坐标到redis", description = "保存司机坐标redis")
    @Parameter(name = "locationDto", description = "坐标参数", required = true)
    @PostMapping("/saveDriverLocation")
    public JSONResult saveDriverLocation(@RequestBody @Valid LocationDto locationDto) {
        return JSONResult.success(driverService.saveDriverLocation(locationDto));
    }

}
